package com.ithiem.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.dubbo.api.QuestionsApi;
import com.itheima.model.domain.Questions;
import com.itheima.model.domain.TestSoul;
import com.ithiem.dubbo.mappers.QuestionsMapper;
import com.ithiem.dubbo.mappers.TestSoulMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class QuestionsApiImpl implements QuestionsApi {
    @Autowired
    private QuestionsMapper questionsMapper;
    @Autowired
    private TestSoulMapper testSoulMapper;

    @Override
    public void saveAll(List<Questions> questionsList) {
        questionsList.forEach(q->questionsMapper.insert(q));

    }

    @Override
    public String queryLevel(String questionId) {//获取回答问题所属问卷等级
        LambdaQueryWrapper<Questions> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Questions::getId,questionId);
        Questions questions = questionsMapper.selectOne(lqw);//查找对应的question

        LambdaQueryWrapper<TestSoul> tlqw = new LambdaQueryWrapper<>();//根据question中的soulId查找等级
        tlqw.eq(TestSoul::getId,questions.getSoulId());
        return testSoulMapper.selectOne(tlqw).getLevel();
    }

    @Override
    public List<Questions> listBySoulId(Long id) {
        return questionsMapper.listBySoulId(id);



    }
}
